import React, { Component } from 'react'
import { connect } from 'react-redux'
import { cartAddAction } from '../../store/actionCreator/homeCreator'
import myaxios from '../../utils/myaxios'
class Index extends Component {
  componentDidMount() {
    myaxios.get("/api/test.json").then(data => {
      console.log(data);
    })
  }
  render() {
    return (
      <div>
        {this.props.num}
        <button onClick={this.props.add}>add</button>
        <h2>首页</h2>
      </div>
    )
  }
}

const mapStateToProps = (state) => {
  return {
    num: state.homeReducer.num
  }
}

const mapDispatchToProps = (dispatch) => {
  return {
    add: function () {
      dispatch(cartAddAction())
    }
  };
}


export default connect(mapStateToProps, mapDispatchToProps)(Index)
